package com.andy.buyu.server.dto;

import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.game.KeepSeet;
import com.andy.buyu.server.game.Room;

import io.netty.buffer.ByteBuf;

/**
 * 更新大厅机台信息
 * @author cuiwm
 */
public class UpdateRoomMessage extends BaseMessage{
	
	private Room room;
	private int index;
    

	public UpdateRoomMessage(Room room, int index) {
		this.room = room;
		this.index = index;
	}

	@Override
	public void writeBody(ByteBuf buf) {
		buf.writeInt(room.getId());
		buf.writeByte(index);
		
		GameUser user = room.getUser(index);
		KeepSeet seet = room.keepSeat(index);
		if(user != null || seet != null) {
			if(user != null){
				writeString(buf, user.getId().toString());
				buf.writeByte(user.getSex());
				buf.writeInt(0);
			}else{
				writeString(buf, seet.getUid().toString());
				buf.writeByte(3);
				buf.writeInt(seet.getLeftTime());
			}
		}else{
			writeString(buf, "0");
			buf.writeByte(0);
			buf.writeInt(0);
		}
		
	}


}